﻿using Microsoft.Xna.Framework.Graphics;
using System;

namespace TinyEngine.Core.Asset
{
    public class SpriteAsset : TinyAsset<Texture2D>
    {
        public SpriteAsset(string name, Texture2D tex) : base(name, string.Empty)
        {
            this.Asset = tex;
            FireUpdated();
        }

        public SpriteAsset(string name, string location) : base(name, location)
        {
        }

        public void Load()
        {
            if (string.IsNullOrEmpty(this.Location))
                return;

            var content = Services.ServiceManager.GetService<Services.ContentManagerService>();
            var loc = this.Location;
            
            loc = loc.Replace(".png", "");
            try
            {
                this.Asset = content.Content.Load<Texture2D>(loc);
                FireUpdated();
            }
            catch (Exception err)
            {
                Console.Write(err);
            }
        }

    }

}
